package com.yiqi.lottery.feature.football.adapter;


import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.text.Html;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.suozhang.framework.utils.T;
import com.yiqi.lottery.R;
import com.yiqi.lottery.common.util.DataManager;
import com.yiqi.lottery.entity.bo.BallMatchBo;
import com.yiqi.lottery.feature.football.view.FootballAllTypeActivity;
import com.yiqi.lottery.framework.DataServer;

import java.util.ArrayList;
import java.util.List;

public class FootballMatchSelectedAdapter extends BaseQuickAdapter<List<BallMatchBo.MatchInfo>, BaseViewHolder> {

    private Context mContext;
    private int mCurrentBetType;
    private OnMatchSelectListener mListener;

    public FootballMatchSelectedAdapter(Context context, int currentBetType) {
        super(currentBetType == 0 || currentBetType == 1 ? R.layout.item_football_match_selected_1 :
                currentBetType == 2 || currentBetType == 4 || currentBetType == 8 ? R.layout.item_football_match_selected_2 :
                        currentBetType == 3 ? R.layout.item_football_match_selected_5 :
                                currentBetType == 5 ? R.layout.item_football_match_selected_3 : R.layout.item_football_match_selected_4
        );
        mContext = context;
        mCurrentBetType = currentBetType;
    }

//        case 0://胜负平
//        case 1://让球胜负平
//        case 3://总进球
//        case 2://比分
//        case 4://半全场
//        case 8://单关2
//        case 5://混头2选1
//        case 6://混合过关
//        case 7://单关1

    @Override
    protected void convert(BaseViewHolder helper, List<BallMatchBo.MatchInfo> item) {



        BallMatchBo.MatchInfo matchInfo;
        if (item.get(0).getPlay() == null) {
            matchInfo = item.get(0);
        } else {
            matchInfo = item.get(0).getPlay();
        }
        ((TextView) helper.getView(R.id.tv1_1)).setText(matchInfo.getLid());
        String no = matchInfo.getNo();
        ((TextView) helper.getView(R.id.tv1_2)).setText(TextUtils.isEmpty(no) ? String.format("%03d", (helper.getAdapterPosition() + 1)) : no.substring(1));
        ((TextView) helper.getView(R.id.tv1_3)).setText(DataServer.getNewTime(matchInfo.getSaleCloseTime(), 10 * 60).split(" ")[1] + "截止");
        if (mCurrentBetType == 0 || mCurrentBetType == 1 || mCurrentBetType == 5) {
            resetAdapterView1(item.get(0), helper.getView(R.id.ll_parent));
        } else if (mCurrentBetType == 2 || mCurrentBetType == 4) {
            resetAdapterView2(item.get(0), helper.getView(R.id.ll_parent), helper.getView(R.id.tvDan));
        } else if (mCurrentBetType == 3) {
            resetAdapterView3(item.get(0), helper.getView(R.id.ll_parent), helper.getView(R.id.tvDan));
        } else if (mCurrentBetType == 6 || mCurrentBetType == 7) {
            resetAdapterView6(item, helper.getView(R.id.ll_parent), helper.getView(R.id.tvDan));
        } else {
            resetAdapterView8(item, helper.getView(R.id.ll_parent), helper.getView(R.id.tvDan));
        }
        if (mListener != null) {
            mListener.reset();
        }
    }

    public int getDanNum() {
        List<List<BallMatchBo.MatchInfo>> list = getData();
        if (list.isEmpty()) {
            return 0;
        }
        int danNum = 0;
        for (List<BallMatchBo.MatchInfo> matchInfos : list) {
            if (matchInfos.get(0).isDan()) {
                ++danNum;
            }
        }
        return danNum;
    }

    private boolean isCanDan() {
        int danNum = getDanNum();
        if (danNum < 7 && danNum < getItemCount() - 1) {
            return true;
        }
        T.showShort("胆的个数要小于所选比赛场次，且小于8个");
        return false;
    }

    private void resetAdapterView8(final List<BallMatchBo.MatchInfo> matchInfos, LinearLayout ll_parent, TextView tvDan) {
        for (BallMatchBo.MatchInfo matchInfo : matchInfos) {
            BallMatchBo.MatchInfo play = matchInfo.getPlay();
            if (play.getIsCheck() == null && !play.getSpTypeDg().isEmpty()) {
                boolean[] isCheck = new boolean[play.getSpTypeDg().size()];
                play.setIsCheck(isCheck);
                isCheck = new boolean[play.getSpTypeDg().size()];
                play.setIsTempCheck(isCheck);
            }
        }
        tvDan.setVisibility(View.INVISIBLE);
 //       Resources resources = mContext.getResources();
//        tvDan.setTag(matchInfos.get(0));
//        if (matchInfos.get(0).isDan()) {
//            tvDan.setBackgroundColor(resources.getColor(R.color.primary_highlight));
//            tvDan.setTextColor(resources.getColor(R.color.primary_comparison));
//        } else {
//            tvDan.setBackgroundColor(resources.getColor(R.color.primary_comparison));
//            tvDan.setTextColor(resources.getColor(R.color.text_primary));
//        }
//        tvDan.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                BallMatchBo.MatchInfo matchInfo = (BallMatchBo.MatchInfo) view.getTag();
//
//                if (!matchInfo.isDan() && !isCanDan()) {
//                    return;
//                }
//
//                matchInfo.setDan(!matchInfo.isDan());
//                if (matchInfo.isDan()) {
//                    view.setBackgroundColor(resources.getColor(R.color.primary_highlight));
//                    ((TextView) view).setTextColor(resources.getColor(R.color.primary_comparison));
//                } else {
//                    view.setBackgroundColor(resources.getColor(R.color.primary_comparison));
//                    ((TextView) view).setTextColor(resources.getColor(R.color.text_primary));
//                }
//                if (mListener != null) {
//                    mListener.reset();
//                }
//            }
//        });
        LinearLayout itemView = (LinearLayout) ll_parent.getChildAt(1);
        ((TextView) itemView.getChildAt(0)).setText(Html.fromHtml(matchInfos.get(0).getPlay().getHn() + "  VS  " + matchInfos.get(0).getPlay().getAn()));
        TextView tv = (TextView) itemView.getChildAt(1);
        tv.setTag(matchInfos);
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                DataManager.getInstance().setTempObject(view.getTag());
                Intent intent = new Intent(mContext, FootballAllTypeActivity.class);
                intent.putExtra("current_type", mCurrentBetType);
                mContext.startActivity(intent);
            }
        });

        int size = matchInfos.size();
        String text = "";
        BallMatchBo.MatchInfo play;
        for (int i = 0; i < size; ++i) {
            play = matchInfos.get(i).getPlay();
            ArrayList<String> list = play.getSpTypeDg();
            String[] dataType = null;
            if (i == 0 || i == 1) {
                dataType = DataServer.FOOT_BALL_SPF;
            } else if (i == 2) {
                dataType = DataServer.FOOT_BALL_ZJQ;
            } else if (i == 3) {
                dataType = DataServer.FOOT_BALL_BQC;
            } else if (i == 4) {
                dataType = DataServer.FOOT_BALL_BF;
            }
            if (dataType != null) {
                int count = list.size();
                for (int j = 0; j < count; ++j) {
                    if (play.isCheck(j)) {
                        text += dataType[j] + "[" + list.get(j) + "] ";
                    }
                }
            }
        }
        if (TextUtils.isEmpty(text)) {
            tv.setText("点击投注");
            tv.setTextSize(13);
            tv.setBackgroundResource(R.drawable.bg_touzhu);
            tv.setTextColor(mContext.getResources().getColor(R.color.text_remind_2));
        } else {
            tv.setText(text);
            tv.setTextSize(10);
            tv.setBackgroundResource(R.drawable.bg_ok);
            tv.setTextColor(mContext.getResources().getColor(R.color.primary_comparison));
        }
    }

    private void resetQitaItm(LinearLayout item, String peilv, List<BallMatchBo.MatchInfo> matchInfos) {
        String[] strs = peilv.split("_");
        item.setVisibility(View.VISIBLE);
        TextView tv = (TextView) item.getChildAt(0);
        tv.setText(strs[0]);
        tv.setTextColor(mContext.getResources().getColor(R.color.primary_comparison));

        tv = (TextView) item.getChildAt(1);
        tv.setTextColor(mContext.getResources().getColor(R.color.primary_comparison));
        tv.setVisibility(View.VISIBLE);
        tv.setText(strs[1]);
        item.setTag(matchInfos);
        item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                DataManager.getInstance().setTempObject(view.getTag());
                Intent intent = new Intent(mContext, FootballAllTypeActivity.class);
                intent.putExtra("current_type", mCurrentBetType);
                mContext.startActivity(intent);
            }
        });
        item.setBackgroundColor(mContext.getResources().getColor(R.color.primary_highlight));
    }

    private void resetAdapterView6(List<BallMatchBo.MatchInfo> matchInfos, LinearLayout ll_parent, TextView tvDan) {
        Resources resources = mContext.getResources();
        if(getItemCount()==1 || mCurrentBetType==7){
            tvDan.setVisibility(View.INVISIBLE);
        }else {
            tvDan.setVisibility(View.VISIBLE);
            tvDan.setTag(matchInfos.get(0));
            if (matchInfos.get(0).isDan()) {
                tvDan.setBackgroundColor(resources.getColor(R.color.primary_highlight));
                tvDan.setTextColor(resources.getColor(R.color.primary_comparison));
            } else {
                tvDan.setBackgroundColor(resources.getColor(R.color.primary_comparison));
                tvDan.setTextColor(resources.getColor(R.color.text_primary));
            }
            tvDan.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    BallMatchBo.MatchInfo matchInfo = (BallMatchBo.MatchInfo) view.getTag();
                    if (!matchInfo.isDan() && !isCanDan()) {
                        return;
                    }
                    matchInfo.setDan(!matchInfo.isDan());
                    if (matchInfo.isDan()) {
                        view.setBackgroundColor(resources.getColor(R.color.primary_highlight));
                        ((TextView) view).setTextColor(resources.getColor(R.color.primary_comparison));
                    } else {
                        view.setBackgroundColor(resources.getColor(R.color.primary_comparison));
                        ((TextView) view).setTextColor(resources.getColor(R.color.text_primary));
                    }
                    if (mListener != null) {
                        mListener.reset();
                    }
                }
            });
        }
        BallMatchBo.MatchInfo play = matchInfos.get(0).getPlay();
        ((TextView) ll_parent.getChildAt(0)).setText(Html.fromHtml(play.getHn() + "  VS  " + play.getAn()));
        int childCount = ll_parent.getChildCount();
        LinearLayout ll, llQita;
        TextView tv;
        ArrayList<String> list;
        for (int i = 1; i < childCount; ++i) {
            if (!(ll_parent.getChildAt(i) instanceof LinearLayout)) {
                continue;
            }
            ll = (LinearLayout) ll_parent.getChildAt(i);
            if (i == childCount - 1) {
                llQita = (LinearLayout) ll.getChildAt(1);
                int count = llQita.getChildCount();
                for (int k = 0; k < count; ++k) {
                    llQita.getChildAt(k).setVisibility(View.GONE);
                }
                int size = matchInfos.size();
                ArrayList<String> selectPeilvs = new ArrayList<>();
                String[] dataType = null;
                boolean[] isCheck;
                for (int j = 2; j < size; ++j) {
                    play = matchInfos.get(j).getPlay();
                    list = play.getSpTypeGg();
                    if (j == 2) {
                        dataType = DataServer.FOOT_BALL_ZJQ;
                    } else if (j == 3) {
                        dataType = DataServer.FOOT_BALL_BQC;
                    } else if (j == 4) {
                        dataType = DataServer.FOOT_BALL_BF;
                    }
                    isCheck = play.getIsCheck();
                    if(isCheck==null){
                        continue;
                    }
                    for (int k = 0; k < isCheck.length; ++k) {
                        if (isCheck[k]) {
                            selectPeilvs.add(dataType[k] + "_" + list.get(k));
                        }
                    }
                }
                if (selectPeilvs.isEmpty()) {
                    LinearLayout llQitaItem;
                    if (count == 0) {
                        llQitaItem = (LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.item_football_match_selected_qita, null);
                        llQita.addView(llQitaItem);
                    } else {
                        llQitaItem = (LinearLayout) llQita.getChildAt(0);
                        llQitaItem.setVisibility(View.VISIBLE);
                    }
                    llQitaItem.getChildAt(1).setVisibility(View.GONE);
                    llQitaItem.getChildAt(2).setVisibility(View.GONE);
                    LinearLayout item = (LinearLayout) llQitaItem.getChildAt(0);
                    item.setBackgroundColor(resources.getColor(R.color.primary_comparison));
                    TextView tv1 = (TextView) item.getChildAt(0);
                    tv1.setText("未选择其他玩法");
                    tv1.setTextColor(mContext.getResources().getColor(R.color.text_primary));
                    item.getChildAt(1).setVisibility(View.GONE);
                    item.setTag(matchInfos);
                    item.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            DataManager.getInstance().setTempObject(view.getTag());
                            Intent intent = new Intent(mContext, FootballAllTypeActivity.class);
                            intent.putExtra("current_type", mCurrentBetType);
                            mContext.startActivity(intent);
                        }
                    });
                } else {
                    int selectNum = selectPeilvs.size();
                    LinearLayout llQitaItem;
                    int row = selectNum % 3 == 0 ? selectNum / 3 : selectNum / 3 + 1;
                    for (int k = 0; k < row; ++k) {
                        if (llQita.getChildCount() <= k) {
                            llQitaItem = (LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.item_football_match_selected_qita, null);
                            llQita.addView(llQitaItem);
                        } else {
                            llQitaItem = (LinearLayout) llQita.getChildAt(k);
                            llQitaItem.setVisibility(View.VISIBLE);
                        }
                        resetQitaItm((LinearLayout) llQitaItem.getChildAt(0), selectPeilvs.get(k * 3), matchInfos);
                        if (k * 3 + 1 < selectNum) {
                            resetQitaItm((LinearLayout) llQitaItem.getChildAt(1), selectPeilvs.get(k * 3 + 1), matchInfos);
                        } else {
                            llQitaItem.getChildAt(1).setVisibility(View.INVISIBLE);
                            llQitaItem.getChildAt(2).setVisibility(View.INVISIBLE);
                        }
                        if (k * 3 + 2 < selectNum) {
                            resetQitaItm((LinearLayout) llQitaItem.getChildAt(2), selectPeilvs.get(k * 3 + 2), matchInfos);
                        } else {
                            llQitaItem.getChildAt(2).setVisibility(View.INVISIBLE);
                        }
                    }
                }

                continue;
            }
            if (i == 1) {
                play = matchInfos.get(0).getPlay();
                if (mCurrentBetType == 6) {
                    list = play.getSpTypeGg();
                } else {
                    list = play.getSpTypeDg();
                }
            } else {
                play = matchInfos.get(1).getPlay();
                if (mCurrentBetType == 6) {
                    list = play.getSpTypeGg();
                } else {
                    list = play.getSpTypeDg();
                }
            }
            for (int j = 0; j < ll.getChildCount(); ++j) {
                if (!(ll.getChildAt(j) instanceof TextView)) {
                    if (mCurrentBetType == 7 && list.isEmpty()) {
                        ll.getChildAt(j).setVisibility(View.GONE);
                    } else {
                        ll.getChildAt(j).setVisibility(View.VISIBLE);
                    }
                    continue;
                }
                int index = j / 2;
                tv = (TextView) ll.getChildAt(j);
                if (i == 1) {
                    if (j == 0) {
                        tv.setText("0");
                        continue;
                    }
                } else {
                    if (j == 0) {
                        int hand = Integer.parseInt(play.getHand());
                        tv.setText(hand > 0 ? "+" + play.getHand() : play.getHand());
                        continue;
                    }
                }

                if (!list.isEmpty()) {
                    tv.setVisibility(View.VISIBLE);
                    if (index == 0) {
                        tv.setText("胜" + list.get(index));
                    } else if (index == 1) {
                        tv.setText("平" + list.get(index));
                    } else {
                        tv.setText("负" + list.get(index));
                    }
                } else {
                    if (index == 0) {
                        tv.setText("未开售");
                    } else if (index == 1) {
                        tv.setVisibility(View.GONE);
                    } else {
                        tv.setVisibility(View.GONE);
                    }
                }
                tv.setTag(index);
                tv.setTag(R.id.tag, play);
                if (!list.isEmpty()) {
                    tv.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            int index = (int) view.getTag();
                            BallMatchBo.MatchInfo play = (BallMatchBo.MatchInfo) view.getTag(R.id.tag);
                            play.setCheck(index, !play.isCheck(index));
                            TextView itemView = (TextView) view;
                            if (play.isCheck(index)) {
                                itemView.setBackgroundColor(resources.getColor(R.color.primary_highlight));
                                itemView.setTextColor(resources.getColor(R.color.primary_comparison));
                            } else {
                                itemView.setBackgroundColor(resources.getColor(R.color.primary_comparison));
                                itemView.setTextColor(resources.getColor(R.color.text_primary));
                            }
                            if (mListener != null) {
                                mListener.reset();
                            }
                        }
                    });
                }
                if (!list.isEmpty() && play.isCheck(index)) {
                    tv.setBackgroundColor(resources.getColor(R.color.primary_highlight));
                    tv.setTextColor(resources.getColor(R.color.primary_comparison));
                } else {
                    tv.setBackgroundColor(resources.getColor(R.color.primary_comparison));
                    tv.setTextColor(resources.getColor(R.color.text_primary));
                }
            }
        }

    }

    private void resetAdapterView3(BallMatchBo.MatchInfo matchInfo, LinearLayout ll_parent, TextView tvDan) {
        Resources resources = mContext.getResources();
        tvDan.setTag(matchInfo);
        if (matchInfo.isDan()) {
            tvDan.setBackgroundColor(resources.getColor(R.color.primary_highlight));
            tvDan.setTextColor(resources.getColor(R.color.primary_comparison));
        } else {
            tvDan.setBackgroundColor(resources.getColor(R.color.primary_comparison));
            tvDan.setTextColor(resources.getColor(R.color.text_primary));
        }
        tvDan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                BallMatchBo.MatchInfo matchInfo = (BallMatchBo.MatchInfo) view.getTag();
                if (!matchInfo.isDan() && !isCanDan()) {
                    return;
                }
                matchInfo.setDan(!matchInfo.isDan());
                if (matchInfo.isDan()) {
                    view.setBackgroundColor(resources.getColor(R.color.primary_highlight));
                    ((TextView) view).setTextColor(resources.getColor(R.color.primary_comparison));
                } else {
                    view.setBackgroundColor(resources.getColor(R.color.primary_comparison));
                    ((TextView) view).setTextColor(resources.getColor(R.color.text_primary));
                }
                if (mListener != null) {
                    mListener.reset();
                }
            }
        });
        ((TextView) ll_parent.getChildAt(0)).setText(Html.fromHtml(matchInfo.getHn() + "  VS  " + matchInfo.getAn()));
        if (matchInfo.getIsCheck() == null && !matchInfo.getSpTypeGg().isEmpty()) {
            boolean[] isCheck = new boolean[matchInfo.getSpTypeGg().size()];
            matchInfo.setIsCheck(isCheck);
        }
        int childCount = ll_parent.getChildCount();
        LinearLayout ll, itemView;
        int hand = Integer.parseInt(matchInfo.getHand());
        for (int i = 1; i < childCount; ++i) {
            if (!(ll_parent.getChildAt(i) instanceof LinearLayout)) {
                continue;
            }
            ll = (LinearLayout) ll_parent.getChildAt(i);
            for (int j = 0; j < ll.getChildCount(); ++j) {
                if (!(ll.getChildAt(j) instanceof LinearLayout)) {
                    continue;
                }
                int index = i / 2 * 4 + j / 2;
                itemView = (LinearLayout) ll.getChildAt(j);
                itemView.setTag(index);
                itemView.setTag(R.id.tag, matchInfo);
                if (!matchInfo.getSpTypeGg().isEmpty()) {
                    itemView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            int index = (int) view.getTag();
                            BallMatchBo.MatchInfo matchInfo = (BallMatchBo.MatchInfo) view.getTag(R.id.tag);
                            matchInfo.setCheck(index, !matchInfo.isCheck(index));
                            LinearLayout itemView = (LinearLayout) view;
                            if (matchInfo.isCheck(index)) {
                                itemView.setBackgroundColor(resources.getColor(R.color.primary_highlight));
                                ((TextView) itemView.getChildAt(0)).setTextColor(resources.getColor(R.color.primary_comparison));
                                ((TextView) itemView.getChildAt(1)).setTextColor(resources.getColor(R.color.primary_comparison));
                            } else {
                                itemView.setBackgroundColor(resources.getColor(R.color.primary_comparison));
                                ((TextView) itemView.getChildAt(0)).setTextColor(resources.getColor(R.color.text_remind_2));
                                ((TextView) itemView.getChildAt(1)).setTextColor(resources.getColor(R.color.text_secondary));
                            }
                            if (mListener != null) {
                                mListener.reset();
                            }
                        }
                    });
                }
                if (index == 0) {
                    ((TextView) itemView.getChildAt(0)).setText(hand < 0 ? " 主胜" : "主不败");
                } else if (index == 1) {
                    ((TextView) itemView.getChildAt(0)).setText(hand < 0 ? " 客不败" : "客胜");
                }
                ((TextView) itemView.getChildAt(0)).setText(DataServer.FOOT_BALL_ZJQ[index]);
                ((TextView) itemView.getChildAt(1)).setText(matchInfo.getSpTypeGg().isEmpty() ? "--" : matchInfo.getSpTypeGg().get(index));
                if (matchInfo.isCheck(index)) {
                    itemView.setBackgroundColor(resources.getColor(R.color.primary_highlight));
                    ((TextView) itemView.getChildAt(0)).setTextColor(resources.getColor(R.color.primary_comparison));
                    ((TextView) itemView.getChildAt(1)).setTextColor(resources.getColor(R.color.primary_comparison));
                } else {
                    itemView.setBackgroundColor(resources.getColor(R.color.primary_comparison));
                    ((TextView) itemView.getChildAt(0)).setTextColor(resources.getColor(R.color.text_remind_2));
                    ((TextView) itemView.getChildAt(1)).setTextColor(resources.getColor(R.color.text_secondary));
                }
            }
        }

    }

    private void resetAdapterView2(BallMatchBo.MatchInfo matchInfo, LinearLayout ll_parent, TextView tvDan) {
        Resources resources = mContext.getResources();
        tvDan.setTag(matchInfo);
        if (matchInfo.isDan()) {
            tvDan.setBackgroundColor(resources.getColor(R.color.primary_highlight));
            tvDan.setTextColor(resources.getColor(R.color.primary_comparison));
        } else {
            tvDan.setBackgroundColor(resources.getColor(R.color.primary_comparison));
            tvDan.setTextColor(resources.getColor(R.color.text_primary));
        }
        tvDan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                BallMatchBo.MatchInfo matchInfo = (BallMatchBo.MatchInfo) view.getTag();
                if (!matchInfo.isDan() && !isCanDan()) {
                    return;
                }
                matchInfo.setDan(!matchInfo.isDan());
                if (matchInfo.isDan()) {
                    view.setBackgroundColor(resources.getColor(R.color.primary_highlight));
                    ((TextView) view).setTextColor(resources.getColor(R.color.primary_comparison));
                } else {
                    view.setBackgroundColor(resources.getColor(R.color.primary_comparison));
                    ((TextView) view).setTextColor(resources.getColor(R.color.text_primary));
                }
                if (mListener != null) {
                    mListener.reset();
                }
            }
        });
        LinearLayout itemView = (LinearLayout) ll_parent.getChildAt(1);
        ((TextView) itemView.getChildAt(0)).setText(Html.fromHtml(matchInfo.getHn() + "  VS  " + matchInfo.getAn()));
        TextView tv = (TextView) itemView.getChildAt(1);
        tv.setTag(matchInfo);
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mListener != null) {
                    mListener.showPopupWindow(mCurrentBetType, (BallMatchBo.MatchInfo) view.getTag(), (TextView) view);
                }
            }
        });

        ArrayList<String> list = matchInfo.getSpTypeGg();
        String[] dataType;
        if (mCurrentBetType == 2) {
            dataType = DataServer.FOOT_BALL_BF;
        } else if (mCurrentBetType == 4) {
            dataType = DataServer.FOOT_BALL_BQC;
        } else {
            dataType = DataServer.FOOT_BALL_BQC;
        }
        if (matchInfo.getIsCheck() == null && !list.isEmpty()) {
            boolean[] isCheck = new boolean[list.size()];
            matchInfo.setIsCheck(isCheck);
            isCheck = new boolean[list.size()];
            matchInfo.setIsTempCheck(isCheck);
        }
        String text = "";
        int size = list.size();
        for (int i = 0; i < size; ++i) {
            matchInfo.setTempCheck(i, matchInfo.isCheck(i));
            if (matchInfo.isCheck(i)) {
                text += dataType[i] + "[" + list.get(i) + "] ";
            }
        }
        if (TextUtils.isEmpty(text)) {
            tv.setText("点击投注");
            tv.setTextSize(13);
            tv.setBackgroundResource(R.drawable.bg_touzhu);
            tv.setTextColor(mContext.getResources().getColor(R.color.text_remind_2));
        } else {
            tv.setText(text);
            tv.setTextSize(10);
            tv.setBackgroundResource(R.drawable.bg_ok);
            tv.setTextColor(mContext.getResources().getColor(R.color.primary_comparison));
        }
    }


    private void resetAdapterView1(BallMatchBo.MatchInfo matchInfo, LinearLayout ll_parent) {
        int childCount = ll_parent.getChildCount();
        LinearLayout itemView;
        Resources resources = mContext.getResources();

        ArrayList<String> list = matchInfo.getSpTypeGg();

        for (int i = 1; i < childCount; ++i) {
            if (i == childCount - 1) {
                TextView tvDan = (TextView) ll_parent.getChildAt(i);
                tvDan.setTag(matchInfo);
                if (matchInfo.isDan()) {
                    tvDan.setBackgroundColor(resources.getColor(R.color.primary_highlight));
                    tvDan.setTextColor(resources.getColor(R.color.primary_comparison));
                } else {
                    tvDan.setBackgroundColor(resources.getColor(R.color.primary_comparison));
                    tvDan.setTextColor(resources.getColor(R.color.text_primary));
                }
                tvDan.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        BallMatchBo.MatchInfo matchInfo = (BallMatchBo.MatchInfo) view.getTag();
                        if (!matchInfo.isDan() && !isCanDan()) {
                            return;
                        }
                        matchInfo.setDan(!matchInfo.isDan());
                        if (matchInfo.isDan()) {
                            view.setBackgroundColor(resources.getColor(R.color.primary_highlight));
                            ((TextView) view).setTextColor(resources.getColor(R.color.primary_comparison));
                        } else {
                            view.setBackgroundColor(resources.getColor(R.color.primary_comparison));
                            ((TextView) view).setTextColor(resources.getColor(R.color.text_primary));
                        }
                        if (mListener != null) {
                            mListener.reset();
                        }
                    }
                });
            }
            if (!(ll_parent.getChildAt(i) instanceof LinearLayout)) {
                continue;
            }
            itemView = (LinearLayout) ll_parent.getChildAt(i);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    int index = (int) view.getTag();
                    BallMatchBo.MatchInfo matchInfo = (BallMatchBo.MatchInfo) view.getTag(R.id.tag);
                    matchInfo.setCheck(index, !matchInfo.isCheck(index));
                    LinearLayout itemView = (LinearLayout) view;
                    if (matchInfo.isCheck(index)) {
                        itemView.setBackgroundColor(resources.getColor(R.color.primary_highlight));
                        if (index == 0) {
                            if (mCurrentBetType == 1) {
                                int hand = Integer.parseInt(matchInfo.getHand());
                                ((TextView) itemView.getChildAt(0)).setText(
                                        Html.fromHtml(matchInfo.getHn() + (hand > 0 ? "+" + matchInfo.getHand() : matchInfo.getHand())));
                            } else {
                                ((TextView) itemView.getChildAt(0)).setText(Html.fromHtml(matchInfo.getHn()));
                            }
                        }
                        ((TextView) itemView.getChildAt(0)).setTextColor(resources.getColor(R.color.primary_comparison));
                        ((TextView) itemView.getChildAt(1)).setTextColor(resources.getColor(R.color.primary_comparison));
                    } else {
                        itemView.setBackgroundColor(resources.getColor(R.color.primary_comparison));
                        if (index == 0) {
                            if (mCurrentBetType == 1) {
                                int hand = Integer.parseInt(matchInfo.getHand());
                                ((TextView) itemView.getChildAt(0)).setText(
                                        Html.fromHtml(matchInfo.getHn() + (hand > 0 ? "<font color=\"#D83220\">+" : "<font color=\"#43C066\">") + matchInfo.getHand() + "</font>"));
                            } else {
                                ((TextView) itemView.getChildAt(0)).setText(Html.fromHtml(matchInfo.getHn()));
                            }
                        }
                        ((TextView) itemView.getChildAt(0)).setTextColor(resources.getColor(R.color.text_primary));
                        ((TextView) itemView.getChildAt(1)).setTextColor(resources.getColor(R.color.text_secondary));
                    }
                    if (mListener != null) {
                        mListener.reset();
                    }
                }
            });
            int index = i / 2;
            itemView.setTag(index);
            itemView.setTag(R.id.tag, matchInfo);
            if (index == 0) {
                if (mCurrentBetType == 5) {
                    int hand = Integer.parseInt(matchInfo.getHand());
                    ((TextView) itemView.getChildAt(1)).setText((hand < 0 ? "主胜" : "主不败") + list.get(index));
                } else {
                    ((TextView) itemView.getChildAt(1)).setText(list.isEmpty() ? "--" : "主胜" + list.get(index));
                }
            } else if (index == 1) {
                if (mCurrentBetType == 5) {
                    ((TextView) itemView.getChildAt(0)).setText(Html.fromHtml(matchInfo.getAn()));
                    int hand = Integer.parseInt(matchInfo.getHand());
                    ((TextView) itemView.getChildAt(1)).setText((hand < 0 ? "客不败" : "客胜") + list.get(index));
                } else {
                    ((TextView) itemView.getChildAt(0)).setText("VS");
                    ((TextView) itemView.getChildAt(1)).setText(list.isEmpty() ? "--" : "平" + list.get(index));
                }
            } else if (index == 2) {
                ((TextView) itemView.getChildAt(0)).setText(Html.fromHtml(matchInfo.getAn()));
                ((TextView) itemView.getChildAt(1)).setText(list.isEmpty() ? "--" : "客胜" + list.get(index));
            }
            if (matchInfo.isCheck(index)) {
                itemView.setBackgroundColor(resources.getColor(R.color.primary_highlight));
                if (index == 0) {
                    if (mCurrentBetType == 1) {
                        int hand = Integer.parseInt(matchInfo.getHand());
                        ((TextView) itemView.getChildAt(0)).setText(
                                Html.fromHtml(matchInfo.getHn() + (hand > 0 ? "+" + matchInfo.getHand() : matchInfo.getHand())));
                    } else {
                        ((TextView) itemView.getChildAt(0)).setText(Html.fromHtml(matchInfo.getHn()));
                    }
                }
                ((TextView) itemView.getChildAt(0)).setTextColor(resources.getColor(R.color.primary_comparison));
                ((TextView) itemView.getChildAt(1)).setTextColor(resources.getColor(R.color.primary_comparison));
            } else {
                itemView.setBackgroundColor(resources.getColor(R.color.primary_comparison));
                if (index == 0) {
                    if (mCurrentBetType == 1) {
                        int hand = Integer.parseInt(matchInfo.getHand());
                        ((TextView) itemView.getChildAt(0)).setText(
                                Html.fromHtml(matchInfo.getHn() + (hand > 0 ? "<font color=\"#D83220\">+" : "<font color=\"#43C066\">") + matchInfo.getHand() + "</font>"));
                    } else {
                        ((TextView) itemView.getChildAt(0)).setText(Html.fromHtml(matchInfo.getHn()));
                    }
                }
                ((TextView) itemView.getChildAt(0)).setTextColor(resources.getColor(R.color.text_primary));
                ((TextView) itemView.getChildAt(1)).setTextColor(resources.getColor(R.color.text_secondary));
            }
        }
    }


    public void setOnMatchSelectListener(OnMatchSelectListener listener) {
        mListener = listener;
    }

    public interface OnMatchSelectListener {
        public void showPopupWindow(int currentType, BallMatchBo.MatchInfo matchInfo, TextView tv);

        public void reset();
    }
}
